﻿@page "/"
@namespace ClassifiedAds.Blazor.Pages
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers
@{
    Layout = null;
}

@using Microsoft.AspNetCore.Authentication
@using Microsoft.IdentityModel.Protocols.OpenIdConnect
@using ClassifiedAds.Blazor.Modules.Core.Services
@using ClassifiedAds.BlazorServerSide
@using System.Globalization

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>ClassifiedAds.BlazorServerSide</title>
    <base href="~/" />
    <link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
    <link href="css/site.css" rel="stylesheet" />
    <link href="ClassifiedAds.BlazorServerSide.styles.css" rel="stylesheet">
</head>
<body>
    @{
        var token = new TokenProvider
        {
            AccessToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.AccessToken),
            RefreshToken = await HttpContext.GetTokenAsync(OpenIdConnectParameterNames.RefreshToken),
            ExpiresAt = DateTimeOffset.TryParse(await HttpContext.GetTokenAsync("expires_at"), CultureInfo.InvariantCulture, DateTimeStyles.None, out var expiration)
                        ? expiration : DateTimeOffset.UtcNow,
        };
    }
    <app>
        <component type="typeof(App)" render-mode="Server" param-InitialState="token" />
    </app>

    <div id="blazor-error-ui">
        <environment include="Staging,Production">
            An error has occurred. This application may no longer respond until reloaded.
        </environment>
        <environment include="Development">
            An unhandled exception has occurred. See browser dev tools for details.
        </environment>
        <a href="" class="reload">Reload</a>
        <a class="dismiss">🗙</a>
    </div>

    <script src="_framework/blazor.server.js"></script>
    <script src="https://unpkg.com/axios/dist/axios.min.js"></script>
    <script src="_content/ClassifiedAds.Blazor.Modules/scripts/interop.js"></script>
</body>
</html>
